
function Node(value) {
  this.value = value;
  this.left = null
  this.right = null
}

var a = new Node("a");
var b = new Node("b");
var c = new Node("c");
var d = new Node("d");
var e = new Node("e");
var f = new Node("f");
var g = new Node("g");
var h = new Node("h");
a.left = b
a.right = c;
b.left = e;
b.right = f;
c.left = g
c.right = h
// 二叉树的搜索
// 树的搜索  图的搜索 爬虫的逻辑  搜索引擎的爬虫算法

// 深度优先搜索
// 一直到下 再返回 再下
// 更适合去探索未知
var s = 'g'
function depSeach(a,tar) {
    if(a == null) return false;
    
    if(a.value == tar)return true;
    else if(depSeach(a.left,s)) return true;
    else return depSeach(a.right,s)

    // let left = depSeach(a.left,s)
    // let right = depSeach(a.right,s)
    // return left || right
}
// console.log(depSeach(a,s))
// 广度优先搜索
// 一层 一层 来
// 更适合探索局域

function scopeSeach(list,tar) {
  if(a == null || list.length == 0) return false;
let  childList = []
  for(let i = 0;i<list.length;i++){
    if(list[i] != null && list[i].value == tar)return true;
    else if(list[i] !== null) childList = childList.concat([list[i].left,list[i].right])
   
  }
  console.log(childList)
return scopeSeach(childList,tar)
  

  // let left = depSeach(a.left,s)
  // let right = depSeach(a.right,s)
  // return left || right
}

console.log(scopeSeach([a],s))


